using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
    public class PromotionsController : BaseController
    {
        private readonly IPromotionsService _iPromotionsService;

        public PromotionsController(IPromotionsService iPromotionsService)
        {
            _iPromotionsService = iPromotionsService;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers })]
        public async Task<IActionResult> Add(RequestCreatePromotionsDto dto)
        {
            return Send(await _iPromotionsService.AddAsync(dto, _supplier.SId));
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers })]
        public async Task<IActionResult> Update(RequestUpdatePromotionsDto dto)
        {
            return Send(await _iPromotionsService.UpdateAsync(dto));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers })]
        public async Task<IActionResult> Delete(RequestIdPromotionsDto dto)
        {
            return Send(await _iPromotionsService.DeleteAsync(dto));
        }

        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="PId"></param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers, CheckLoginRoles.administrators })]
        public async Task<IActionResult> Detail(RequestIdPromotionsDto dto)
        {
            return Send(await _iPromotionsService.DetailAsync(dto));
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page">当前是第几页</param>
        /// <param name="limit">一页有多少条数据</param>
        /// <param name="key">要查询的关键字</param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers, CheckLoginRoles.administrators })]
        public async Task<IActionResult> Pagination(int page, int limit, string? key)
        {
            return Send(await _iPromotionsService.PaginationAsync(page, limit, key));
        }
    }
}
